/**
 * Created by lizhe on 2018/4/17.
 */
var datas = [];
var first = [];
var second = [];
var third = [];
//获取一二级栏目列表
$(document).ready(function(){
    queryList();
    queryLink();
});

function queryList(){
    $.ajax({
        url : urladdr + "/web/menu/list",
        method : "GET",
        data : {

        },
        success : function(data){
            if(data.code == 0){
                datas.splice(0,datas.length);
                first.splice(0,first.length);
                second.splice(0,second.length);
                third.splice(0,third.length);
                $("#menu").empty();
                $.each(data.data,function(i,date){
                    var d ={
                        id:date.id,name:date.title,parentId:date.parentId,height:date.height,type:date.type,icon:date.icon
                    };
                    datas.push(d);
                });
                for(var i =0;i<datas.length;i++){
                    if(datas[i].height==0){
                        var d = {
                            id:datas[i].id,name:datas[i].name,parentId:datas[i].parentId,height:datas[i].height,type:datas[i].type,icon:datas[i].icon
                        };
                        first.push(d);
                    }
                    if(datas[i].height==1){
                        d = {
                            id:datas[i].id,name:datas[i].name,parentId:datas[i].parentId,height:datas[i].height,type:datas[i].type,icon:datas[i].icon
                        };
                        second.push(d);
                    }
                    if(datas[i].height==2){
                        d = {
                            id:datas[i].id,name:datas[i].name,parentId:datas[i].parentId,height:datas[i].height,type:datas[i].type,icon:datas[i].icon
                        };
                        third.push(d);
                    }
                }

                document.getElementById("menu").innerHTML = document.getElementById("menu").innerHTML +
                    '<li>'+
                    '<a href="index.html">'+
                    '<div class="columnMidLink"></div>'+
                    '<i class="fa"><img src="images/9902.png"></i>'+
                    '<span style="margin-left: 30px">校园首页</span>'+
                    '<div class="columnPoint"></div>'+
                    '</a>'+
                    '<div class="columnLink"></div>'+
                    '</li>';
                //自定拟部分栏目
                $.each(first,function(i,date){
                    var x=0;
                    var content = '<ul class="menu-academico-sub">';
                    $.each(second,function(j,dateJ){
                        if(dateJ.type==1){
                            var href2 = "article.html?menuId="+dateJ.id+"&type="+date.type+"&next=1";
                        }else if(dateJ.type == 2){
                            href2 = "album.html?menuId="+dateJ.id+"&type="+date.type+"&next=1";
                        }else if(dateJ.type == 3){
                            href2 = "teacher.html?menuId="+dateJ.id+"&type="+date.type+"&next=1";
                        }else if(dateJ.type == 4){
                            href2 = "student.html?menuId="+dateJ.id+"&type="+date.type+"&next=1";
                        }else if(dateJ.type == 5){
                            var id = queryArticleId(dateJ.id);
                            href2 = "text.html?menuId="+dateJ.id+"&id="+id+"&next=1";
                        }else if(dateJ.type == 6){
                            href2 = "teacher2.html?menuId="+dateJ.id+"&type="+date.type+"&next=1";
                        }
                        if(dateJ.parentId == date.id){
                            x=1;
                            content = content + '<li><b class="hidden">'+dateJ.id+'</b>' +
                                '<a href='+href2+' style="background: #1B4A2B;box-shadow: 2px 4px 4px 0 rgba(0,0,0,0.50);" onmousemove="aHover(this)" onmouseout="aMove(this)">'+dateJ.name+'</a>' +
                                '<div class="columnLink2"></div></li>'
                        }
                    });
                    if(x==1){
                        var href = "#";
                    }else{
                        if(date.type==1){
                            href = "article.html?menuId="+date.id+"&type="+date.type+"&next=0";
                        }else if(date.type == 2){
                            href = "album.html?menuId="+date.id+"&type="+date.type+"&next=0";
                        }else if(date.type == 3){
                            href = "teacher.html?menuId="+date.id+"&type="+date.type+"&next=0";
                        }else if(date.type == 4){
                            href = "student.html?menuId="+date.id+"&type="+date.type+"&next=0";
                        }else if(date.type == 5){
                            var id = queryArticleId(date.id);
                            href = "text.html?menuId="+date.id+"&id="+id+"&next=0";
                        }else if(date.type == 6){
                            href = "teacher2.html?menuId="+date.id+"&type="+date.type+"&next=0";
                        }
                    }
                    if(content == '<ul class="menu-academico-sub">'){
                        document.getElementById("menu").innerHTML = document.getElementById("menu").innerHTML +
                            '<li>'+
                            '<a href='+href+'>'+
                            '<div class="columnMidLink"></div>'+
                            '<i class="fa"><img src="'+date.icon+'"></i>'+
                            '<b class="hidden">'+date.id+'</b>'+
                            '<span style="margin-left: 30px">'+date.name+'</span>'+
                            '<div class="columnPoint"></div>'+
                            '</a>'+
                            '<div class="columnLink"></div>'+
                            '</li>'
                    }else{
                        document.getElementById("menu").innerHTML = document.getElementById("menu").innerHTML +
                            '<li>'+
                            '<a href='+href+'>'+
                            '<div class="columnMidLink"></div>'+
                            '<i class="fa"><img src="'+date.icon+'"></i>'+
                            '<b class="hidden">'+date.id+'</b>'+
                            '<span style="margin-left: 30px">'+date.name+'</span>'+
                            '<div class="columnPoint"></div>'+
                            '</a>'+
                            '<div class="columnLink"></div>'+
                            content+
                            '</ul>' +
                            '</li>'
                    }
                });
                //链接栏目
                document.getElementById("menu").innerHTML = document.getElementById("menu").innerHTML +
                    '<li>'+
                    '<a href="schoolLink.html">'+
                    '<div class="columnMidLink"></div>'+
                    '<i class="fa"><img src="images/9_06.png"></i>'+
                    '<span style="margin-left: 30px">学校链接</span>'+
                    '<div class="columnPoint"></div>'+
                    '</a>'+
                    '<div class="columnLink"></div>'+
                    '</li>'+
                    '<li>'+
                    '<a href="otherLink.html" style="background-color:#3e8937;">'+
                    '<div class="columnMidLink" style="visibility: visible"></div>'+
                    '<i class="fa"><img src="images/9908.png"></i>'+
                    '<span style="margin-left: 30px">其他链接</span>'+
                    '<div class="columnPoint" style="visibility: visible"></div>'+
                    '</a>'+
                    '<div class="columnLink"></div>'+
                    '</li>'+
                    '<li>'+
                    '<div align="center" style="background: rgb(38, 93, 58);height: 278px">'+
                    '<img src="images/code.png" class="codeImg">'+
                    '<div class="codeDiv">扫一扫关注</div>'+
                    '</div>'+
                    '</li>'
            }else if(data.code == 401){
                location.href = "index.html"
            }else{
                modalinfo(data.msg);
            }
        }
    });
}

function queryLink(){
    $.ajax({
        url : urladdr + "/web/link/list",
        method : "GET",
        data : {
            type:2
        },
        success : function(data){
            if(data.code == 0){
                $("#content").empty();
                $.each(data.data,function(i,date){
                    var icon = imgUrl + date.icon;
                    document.getElementById("content").innerHTML = document.getElementById("content").innerHTML +
                        '<div class="linkDiv" onclick=openUrl("'+date.url+'")>'+
                        '<div>'+
                        '<img src="'+icon+'" class="linkImg">'+
                        '</div>'+
                        '<div class="linkTitle">'+date.title+'</div>'+
                        '</div>'
                });
            }else if(data.code == 401){
                location.href = "index.html"
            }else{
                modalinfo(data.msg);
            }
        }
    });

}
